#include <openssl/sm4.h>
#include <stdio.h>
#include <string.h>

void sm4_encrypt_decrypt() {
    unsigned char key[16] = "1234567890abcdef"; // 128-bit key
    unsigned char plaintext[16] = "Hello, SM4!";
    unsigned char ciphertext[16];
    unsigned char decrypted[16];

    // SM4 Encrypt
    SM4_encrypt(key, plaintext, ciphertext);
    printf("Ciphertext: ");
    for (int i = 0; i < 16; i++) {
        printf("%02x", ciphertext[i]);
    }
    printf("\n");

    // SM4 Decrypt
    SM4_decrypt(key, ciphertext, decrypted);
    printf("Decrypted: %s\n", decrypted);
}

int main() {
    sm4_encrypt_decrypt();
    return 0;
}

